<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件</title>
</head>

<body>
  <h1>点名</h1>
  <button class="start">开始</button>
  <button class="end">结束</button>
  <div></div>
  <script>
    const arr = ['张三', '李四', '王五']
    const start = document.querySelector('.start')
    const end = document.querySelector('.end')
    const div = document.querySelector('div')
    let timer = 0
    let random = 0
    start.addEventListener('click', function () {
      timer = setInterval(function () {
        random = Math.floor(Math.random() * arr.length)
        // console.log(random);
        div.innerHTML = '抽到的名字是' + arr[random]
      }, 35)

      if (arr.length === 1) {
        start.disabled = true
      }
    }
    )

    end.addEventListener('click', function () {
      arr.splice(random, 1)
      clearInterval(timer)
    })
  </script>
</body>

</html>